﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace FileOperatorWPF
{
    public class DirectoryItem
    {
        public string Name { get; set; }
        public List<DirectoryItem> SubDirectories { get; set; }
        public bool IsLoaded { get; set; }
        public bool IsFile { get; set; }

        public DirectoryItem(string name, bool type)
        {
            Name = name;
            SubDirectories = new List<DirectoryItem>();
            IsLoaded = false;
            IsFile = type;
        }
        public void LoadSubDirectories()
        {
            if (!IsLoaded)
            {             
                // 子文件夹
                string[] subDirectories = Directory.GetDirectories(Name);
                foreach (string subDir in subDirectories)
                {
                    SubDirectories.Add(new DirectoryItem(subDir, false));
                }
                // 子文件
                string[] subFiles = Directory.GetFiles(Name);
                foreach (string subFile in subFiles)
                {
                    SubDirectories.Add(new DirectoryItem(subFile, true));
                }
            }                              
            IsLoaded = true;
        }
    }
}
